'use strict';
/*
 * @name 莫凡编译打包文件,用正则表达式进行过滤
 * @version 1.0.1
 * @author xiech
 * @Time 2019年10月29日10:36:45
 */

const zipdir = require('zip-dir');
const path = require('path');

const filePath = path.resolve('./');
const myDate = new Date();
const year = myDate.getFullYear();
const month = (myDate.getMonth() + 1) < 10 ? '0' + (myDate.getMonth() + 1) : (myDate.getMonth() + 1);
const date = myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate();
const hours = myDate.getHours() < 10 ? '0' + myDate.getHours() : myDate.getHours();
const minutes = myDate.getMinutes() < 10 ? '0' + myDate.getMinutes() : myDate.getMinutes();
const seconds = myDate.getSeconds() < 10 ? '0' + myDate.getSeconds() : myDate.getSeconds();
const name = './MF-Zip' + year + month + date + hours + minutes + seconds + '.zip';
zipdir(filePath, {
  filter: path => !/\/node_modules|\/\.git|\.zip$|\.DS_Store$|\\node_modules|\\\.git|\/run|\/logs|\/typings|\/test/.test(path),
  saveTo: name,
}, function(err, buffer) {
  if (!err) {
    console.log('压缩成功:', name, buffer);
  } else {
    console.log(err);
  }
});
